<template>
    <div>
         <!-- 面包屑导航区 -->
        <el-breadcrumb separator-class="el-icon-arrow-right">
        <el-breadcrumb-item :to="{ path: '/home' }">首页</el-breadcrumb-item>
        <el-breadcrumb-item>系统管理</el-breadcrumb-item>
        <el-breadcrumb-item>基础设置</el-breadcrumb-item>
        </el-breadcrumb>
        <el-card>
            <el-tabs v-model="activeName" @tab-click="handleClick">
                <el-tab-pane label="院系管理" name="first">
                    <!-- 搜索 添加 -->
                    <el-row :gutter="20">
                        <el-col :span="10">
                            <el-input placeholder="请输入内容" v-model="queryInfo.query" clearable @clear="getDepartList">
                                <el-button type="success" slot="append" icon="el-icon-search" @click="getDepartList"></el-button>
                            </el-input>
                        </el-col>
                        <el-col :span="13">
                            <el-button class="right" type="primary" @click="showAddDepDialog">添加院系</el-button>
                        </el-col>
                    </el-row>
                     <el-table :data="departList" border stripe :header-cell-style="table_header" empty-text="暂无数据">
                        <!-- 索引列 -->
                        <el-table-column type="index" label="序号" width="50px" align="center"></el-table-column>
                        <el-table-column label="院系名称" prop="name" align="center"></el-table-column>
                        <el-table-column label="操作" width="300px" align="center">
                            <template slot-scope="scope">
                                <el-button type="primary" icon="el-icon-edit" size="mini" @click="showEditDepDialog(scope.row)">编辑</el-button>
                                <el-button type="danger" icon="el-icon-delete" size="mini" @click="removeDepartById(scope.row)">删除</el-button>
                            </template>
                        </el-table-column>
                    </el-table>

                    <!-- 分页区域 -->
                    <div class="pager-box">
                        <el-pagination
                            @size-change="handleSizeChange"
                            @current-change="handleCurrentChange"
                            :current-page="queryInfo.pageNum"
                            :page-sizes="[2, 5, 10, 15]"
                            :page-size="queryInfo.pageSize"
                            layout="total, sizes, prev, pager, next, jumper"
                            prev-text="上一页"
                            next-text="下一页"
                            :total="total"
                            background
                            hide-on-single-page
                        ></el-pagination>
                    </div>
                    <!-- 添加院系 -->
                    <el-dialog
                    title="添加院系"
                    :visible.sync="addDepDialogVisible"
                    width="35%"
                    @close="resetForm('addDepFormRef')"
                    >
                         <el-form
                            :model="DepForm"
                            ref="addDepFormRef"
                            :rules="DepFormRules"
                            label-width="80px"
                        >
                            <el-form-item label="院系名称" prop="name">
                                <el-input v-model="DepForm.name"></el-input>
                            </el-form-item>
                        </el-form>
                        <span slot="footer" class="dialog-footer">
                            <el-button @click="AddDepDialogVisible = false">取 消</el-button>
                            <el-button type="primary" @click="addDep">确 定</el-button>
                        </span>
                    </el-dialog>
                    
                    <!-- 编辑院系 -->
                    <el-dialog
                    title="编辑院系"
                    :visible.sync="editDepDialogVisible"
                    width="35%"
                    @close="resetForm('editDepFormRef')"
                    >
                         <el-form
                            :model="DepForm"
                            ref="editDepFormRef"
                            :rules="DepFormRules"
                            label-width="80px"
                        >
                            <el-form-item label="院系名称" prop="name">
                                <el-input v-model="DepForm.name"></el-input>
                            </el-form-item>
                        </el-form>
                        <span slot="footer" class="dialog-footer">
                            <el-button @click="editDepDialogVisible = false">取 消</el-button>
                            <el-button type="primary" @click="editDep">确 定</el-button>
                        </span>
                    </el-dialog>
                </el-tab-pane>
                <el-tab-pane label="专业管理" name="second">
                    <!-- 搜索 添加 -->
                    <el-row :gutter="20">
                        <el-col :span="10">
                            <el-input placeholder="请输入内容" v-model="queryInfo.query" clearable @clear="getMajorList">
                                <el-button type="success" slot="append" icon="el-icon-search" @click="getMajorList"></el-button>
                            </el-input>
                        </el-col>
                        <el-col :span="13">
                            <el-button class="right" type="primary" @click="showAddMajorDialog">添加专业</el-button>
                        </el-col>
                    </el-row>
                     <el-table :data="majorList" border stripe :header-cell-style="table_header" empty-text="暂无数据">
                        <!-- 索引列 -->
                        <el-table-column type="index" label="序号" width="50px" align="center"></el-table-column>
                        <el-table-column label="专业名称" prop="name" align="center"></el-table-column>
                        <el-table-column label="所属院系" prop="department.name" align="center"></el-table-column>
                        <el-table-column label="类别" prop="level" align="center">
                            <template slot-scope="scope">
                                <el-tag v-if="scope.row.level === '本科'">本科</el-tag>
                                <el-tag type="success" v-else-if="scope.row.level === '硕士'">硕士</el-tag>
                            </template>
                        </el-table-column>
                        <el-table-column label="操作" width="300px" align="center">
                            <template slot-scope="scope">
                                <el-button type="primary" icon="el-icon-edit" size="mini" @click="showEditMajorDialog(scope.row)">编辑</el-button>
                                <el-button type="danger" icon="el-icon-delete" size="mini" @click="removeMajorById(scope.row)">删除</el-button>
                            </template>
                        </el-table-column>
                    </el-table>
                     <!-- 添加专业的对话框 -->
                     <el-dialog title="添加专业" :visible.sync="addMajorDialogVisible" width="50%" @close="resetForm('addMajorFormRef')">
                        <el-form
                            :model="MajorForm"
                            :rules="MajorFormRules"
                            ref="addMajorFormRef"
                            label-width="100px"
                        >
                            <el-form-item label="专业名称：" prop="name">
                                <el-input v-model="MajorForm.name"></el-input>
                            </el-form-item>
                            <el-form-item label="所属院系：">
                                 <el-select v-model="MajorForm.department_id" filterable placeholder="请选择">
                                    <el-option
                                    v-for="item in departList"
                                    :key="item.id"
                                    :label="item.name"
                                    :value="item.id">
                                    </el-option>
                                </el-select>
                            </el-form-item>
                            <el-form-item label="专业类别：">
                                 <el-select v-model="MajorForm.level" filterable placeholder="请选择">
                                    <el-option label="本科" value="本科"> </el-option>
                                    <el-option label="硕士" value="硕士"> </el-option>
                                </el-select>
                            </el-form-item>
                            <el-alert
                                title="注意：必须选择所属院系"
                                type="warning">
                            </el-alert>
                        </el-form>
                        <span slot="footer" class="dialog-footer">
                            <el-button @click="addMajorDialogVisible = false">取 消</el-button>
                            <el-button type="primary" @click="addMajor">确 定</el-button>
                        </span>
                    </el-dialog>

                    <!-- 编辑专业的对话框 -->
                     <el-dialog title="编辑专业" :visible.sync="editMajorDialogVisible" width="50%" @close="resetForm('editMajorFormRef')">
                        <el-form
                            :model="MajorForm"
                            :rules="MajorFormRules"
                            ref="editMajorFormRef"
                            label-width="100px"
                        >
                            <el-form-item label="专业名称：" prop="name">
                                <el-input v-model="MajorForm.name"></el-input>
                            </el-form-item>
                            <el-form-item label="所属院系：">
                                 <el-select v-model="MajorForm.department_id" filterable placeholder="请选择">
                                    <el-option
                                    v-for="item in departList"
                                    :key="item.id"
                                    :label="item.name"
                                    :value="item.id">
                                    </el-option>
                                </el-select>
                            </el-form-item>
                            <el-form-item label="专业类别：">
                                 <el-select v-model="MajorForm.level" filterable placeholder="请选择">
                                    <el-option label="本科" value="本科"> </el-option>
                                    <el-option label="硕士" value="硕士"> </el-option>
                                </el-select>
                            </el-form-item>
                            <el-alert
                                title="注意：必须选择所属院系"
                                type="warning">
                            </el-alert>
                        </el-form>
                        <span slot="footer" class="dialog-footer">
                            <el-button @click="editMajorDialogVisible = false">取 消</el-button>
                            <el-button type="primary" @click="editMajor">确 定</el-button>
                        </span>
                    </el-dialog>
                </el-tab-pane>
                <el-tab-pane label="学期管理" name="third">
                     <!-- 搜索 添加 -->
                    <el-row :gutter="20">
                        <el-col :span="10">
                            <el-input placeholder="请输入内容" v-model="queryInfo.query" clearable @clear="getSemesterList">
                                <el-button type="success" slot="append" icon="el-icon-search" @click="getSemesterList"></el-button>
                            </el-input>
                        </el-col>
                        <el-col :span="13">
                            <el-button class="right" type="primary" @click="showAddSemesterDialog">添加学期</el-button>
                        </el-col>
                    </el-row>
                     <el-table :data="semesterList" border stripe :header-cell-style="table_header" empty-text="暂无数据">
                        <!-- 索引列 -->
                        <el-table-column type="index" label="序号" width="50px" align="center"></el-table-column>
                         <el-table-column label="学年" prop="school_year" align="center"></el-table-column>
                        <el-table-column label="学期名称" prop="name" align="center"></el-table-column>
                        <el-table-column label="操作" width="300px" align="center">
                            <template slot-scope="scope">
                                <el-button type="primary" icon="el-icon-edit" size="mini" @click="showEditSemesterDialog(scope.row)">编辑</el-button>
                                <el-button type="danger" icon="el-icon-delete" size="mini" @click="removeSemesterById(scope.row)">删除</el-button>
                            </template>
                        </el-table-column>
                    </el-table>

                    <!-- 分页区域 -->
                    <div class="pager-box">
                        <el-pagination
                            @size-change="handleSizeChange"
                            @current-change="handleCurrentChange"
                            :current-page="queryInfo.pageNum"
                            :page-sizes="[2, 5, 10, 15]"
                            :page-size="queryInfo.pageSize"
                            layout="total, sizes, prev, pager, next, jumper"
                            prev-text="上一页"
                            next-text="下一页"
                            :total="total"
                            background
                            hide-on-single-page
                        ></el-pagination>
                    </div>
                    <!-- 添加学期 -->
                    <el-dialog
                    title="添加学期"
                    :visible.sync="addSemesterDialogVisible"
                    width="35%"
                    @close="resetForm('addSemesterFormRef')"
                    >
                         <el-form
                            :model="SemesterForm"
                            ref="addSemesterFormRef"
                            :rules="SemesterFormRules"
                            label-width="80px"
                        >
                             <el-form-item label="学年" prop="school_year">
                                 <el-input v-model="SemesterForm.school_year"></el-input>
                             </el-form-item>
                            <el-form-item label="学期名称" prop="name">
                                <el-input v-model="SemesterForm.name"></el-input>
                            </el-form-item>
                        </el-form>
                        <span slot="footer" class="dialog-footer">
                            <el-button @click="AddSemesterpDialogVisible = false">取 消</el-button>
                            <el-button type="primary" @click="addSemester">确 定</el-button>
                        </span>
                    </el-dialog>
                    
                    <!-- 编辑学期 -->
                    <el-dialog
                    title="编辑学期"
                    :visible.sync="editSemesterDialogVisible"
                    width="35%"
                    @close="resetForm('editSemesterFormRef')"
                    >
                         <el-form
                            :model="SemesterForm"
                            ref="editSemesterFormRef"
                            :rules="SemesterFormRules"
                            label-width="80px"
                        >
                             <el-form-item label="学年" prop="school_year">
                                 <el-input v-model="SemesterForm.school_year"></el-input>
                             </el-form-item>
                            <el-form-item label="学期名称" prop="name">
                                <el-input v-model="SemesterForm.name"></el-input>
                            </el-form-item>
                        </el-form>
                        <span slot="footer" class="dialog-footer">
                            <el-button @click="editSemesterDialogVisible = false">取 消</el-button>
                            <el-button type="primary" @click="editSemester">确 定</el-button>
                        </span>
                    </el-dialog>
                </el-tab-pane>
                <el-tab-pane label="年级管理" name="four">
                     <!-- 搜索 添加 -->
                    <el-row :gutter="20">
                        <el-col :span="10">
                            <el-input placeholder="请输入内容" v-model="queryInfo.query" clearable @clear="getGradeList">
                                <el-button type="success" slot="append" icon="el-icon-search" @click="getGradeList"></el-button>
                            </el-input>
                        </el-col>
                        <el-col :span="13">
                            <el-button class="right" type="primary" @click="showAddGradeDialog">添加年级</el-button>
                        </el-col>
                    </el-row>
                     <el-table :data="gradeList" border stripe :header-cell-style="table_header" empty-text="暂无数据">
                        <!-- 索引列 -->
                        <el-table-column type="index" label="序号" width="50px" align="center"></el-table-column>
                        <el-table-column label="年级名称" prop="name" align="center"></el-table-column>
                        <el-table-column label="操作" width="300px" align="center">
                            <template slot-scope="scope">
                                <el-button type="primary" icon="el-icon-edit" size="mini" @click="showEditGradeDialog(scope.row)">编辑</el-button>
                                <el-button type="danger" icon="el-icon-delete" size="mini" @click="removeGradeById(scope.row)">删除</el-button>
                            </template>
                        </el-table-column>
                    </el-table>

                    <!-- 分页区域 -->
                    <div class="pager-box">
                        <el-pagination
                            @size-change="handleSizeChange"
                            @current-change="handleCurrentChange"
                            :current-page="queryInfo.pageNum"
                            :page-sizes="[2, 5, 10, 15]"
                            :page-size="queryInfo.pageSize"
                            layout="total, sizes, prev, pager, next, jumper"
                            prev-text="上一页"
                            next-text="下一页"
                            :total="total"
                            background
                            hide-on-single-page
                        ></el-pagination>
                    </div>
                    <!-- 添加年级 -->
                    <el-dialog
                    title="添加年级"
                    :visible.sync="addGradeDialogVisible"
                    width="35%"
                    @close="resetForm('addGradeFormRef')"
                    >
                         <el-form
                            :model="GradeForm"
                            ref="addGradeFormRef"
                            :rules="GradeFormRules"
                            label-width="80px"
                        >
                            <el-form-item label="年级名称" prop="name">
                                <el-input v-model="GradeForm.name"></el-input>
                            </el-form-item>
                        </el-form>
                        <span slot="footer" class="dialog-footer">
                            <el-button @click="AddGradepDialogVisible = false">取 消</el-button>
                            <el-button type="primary" @click="addGrade">确 定</el-button>
                        </span>
                    </el-dialog>
                    
                    <!-- 编辑年级 -->
                    <el-dialog
                    title="编辑年级"
                    :visible.sync="editGradeDialogVisible"
                    width="35%"
                    @close="resetForm('editGradeFormRef')"
                    >
                         <el-form
                            :model="GradeForm"
                            ref="editGradeFormRef"
                            :rules="GradeFormRules"
                            label-width="80px"
                        >
                            <el-form-item label="年级名称" prop="name">
                                <el-input v-model="GradeForm.name"></el-input>
                            </el-form-item>
                        </el-form>
                        <span slot="footer" class="dialog-footer">
                            <el-button @click="editGradeDialogVisible = false">取 消</el-button>
                            <el-button type="primary" @click="editGrade">确 定</el-button>
                        </span>
                    </el-dialog>
                </el-tab-pane>
            </el-tabs>
        </el-card>
    </div>
</template>
<script>
export default {
  data() {
      return {
        queryInfo: {
            query: '',
            // 当前页数
            pageNum: 1,
            // 每页显示多少数据
            pageSize: 10,
        },
        total: 0,
        activeName: 'first',
        
        departList: [],
        majorList: [],
        semesterList: [],
        gradeList: [],

        addDepDialogVisible: false,
        editDepDialogVisible: false,
        addMajorDialogVisible: false,
        editMajorDialogVisible: false,
        addSemesterDialogVisible: false,
        editSemesterDialogVisible: false,
        addGradeDialogVisible: false,
        editGradeDialogVisible: false,

        DepForm:{
            name: "",
        },
        MajorForm:{
            department_id: null,
            name: "",
        },
        SemesterForm:{
            name: "",
        },
        GradeForm:{
              name: "",
          },
        DepFormRules: {
            name: [
            { required: true, message: '请输入院系名称', trigger: 'blur' },
            { min: 3, max: 20, message: '长度在 3 到 20 个字符', trigger: 'blur' }
          ],
        },
        MajorFormRules: {
            department_id: [
            { required: true, message: '请输所属院系', trigger: 'blur' },
          ],
            name: [
            { required: true, message: '请输入专业名称', trigger: 'blur' },
            { min: 3, max: 20, message: '长度在 3 到 20 个字符', trigger: 'blur' }
          ],
        },
        SemesterFormRules: {
            school_year: [
                { required: true, message: '请输入学期名称', trigger: 'blur' },
            ],
            name: [
            { required: true, message: '请输入学期名称', trigger: 'blur' },
          ],
        },
        GradeFormRules: {
            name: [
                  { required: true, message: '请输入年级名称', trigger: 'blur' },
            ],
          },
      };
    },
    created(){
        this.getDepartList();
    },
    methods: {
        handleClick(tab, event) {
            if (tab.paneName === 'second'){
                this.getMajorList();
            }else if (tab.paneName === "third"){
                this.getSemesterList()
            }else if (tab.paneName === "four"){
                this.getGradeList()
            }else{
                this.getDepartList()
            }
        },
        table_header(row, column, rowIndex, columnIndex){
            return 'background-color: rgb(102,177,255);color: white;font-size:14px;'
        },
          // 监听 pagesize改变的事件
        handleSizeChange (newSize) {
            // console.log(newSize)
            this.queryInfo.pageSize = newSize
            this.getDepartList()
        },
        // 监听 页码值 改变事件
        handleCurrentChange (newSize) {
            // console.log(newSize)
            this.queryInfo.pageNum = newSize
            this.getDepartList()
        },
        showAddDepDialog(){
            this.DepForm = {}
            this.addDepDialogVisible = true
        },
        showAddMajorDialog(){
            this.MajorForm = {}
            this.addMajorDialogVisible = true
        },
        showAddSemesterDialog(){
            this.SemesterForm = {}
            this.addSemesterDialogVisible = true
        },
        showAddGradeDialog(){
            this.GradeForm = {}
            this.addGradeDialogVisible = true
        },
        // 编辑院系
        showEditDepDialog (role) {
            this.DepForm = role
            this.editDepDialogVisible = true
        },
        showEditMajorDialog (row) {
            this.MajorForm = row
            this.editMajorDialogVisible = true
        },
        // 
        showEditSemesterDialog (row) {
            this.SemesterForm = row
            this.editSemesterDialogVisible = true
        },
        showEditGradeDialog (row) {
            this.GradeForm = row
            this.editGradeDialogVisible = true
        },
        resetForm(formName) {
            this.$refs[formName].resetFields();
        },        
        async getDepartList(){
            const { data: res, status: status } = await this.axios.get("department/getDepartmentList", {params: this.queryInfo})
            if (status !== 200) {
                return this.$message.error('获取院系列表失败！')
            }
            this.departList = res.data.departments
            this.queryInfo.total = res.data.total
        },
        async getMajorList(){
            const { data: res, status: status } = await this.axios.get("major/getMajorList", {params: this.queryInfo})
            if (status !== 200) {
                return this.$message.error('获取院系列表失败！')
            }
            this.majorList = res.data.Majors;
            this.total = res.data.total
        },
        async getSemesterList(){
            const { data: res, status: status } = await this.axios.get("semester/getSemesterList", {params: this.queryInfo})
            if (status !== 200) {
                return this.$message.error('获取院系列表失败！')
            }
            this.semesterList = res.data.semesters
            this.queryInfo.total = res.data.total
        },
        async getGradeList(){
            const { data: res, status: status } = await this.axios.get("grade/getGradeList", {params: this.queryInfo})
            if (status !== 200) {
                return this.$message.error('获取院系列表失败！')
            }
            this.gradeList = res.data.grades;
            this.queryInfo.total = res.data.total;
        },
        addDep() {
            this.$refs.addDepFormRef.validate(async valid => {
            if (valid) {
                const {data: res, status: status} = await this.axios.post("department/addOneDepart", this.DepForm)
                if (status !== 200){
                    return this.$message.error("添加院系失败")
                }
                this.$message.success("添加院系成功")
                this.addDepDialogVisible = false
                this.getDepartList()
            }
            return;
            });
        },
        // 添加专业
        addMajor () {
            if (!this.MajorForm.department_id) {
                return this.$message.error("情选择所属院系") 
            }
            this.$refs.addMajorFormRef.validate(async valid => {
                if (!valid) return
                const { data: res, status: status } = await this.axios.post('major/addMajor', this.MajorForm)
                if (status !== 200) {
                    return this.$message.error('添加专业失败！')
                }
                this.$message.success('添加专业成功！')
                this.getMajorList()
                this.addMajorDialogVisible = false
            })
        },
        // 添加专业
        addSemester () {
            this.$refs.addSemesterFormRef.validate(async valid => {
                if (!valid) return
                const { data: res, status: status } = await this.axios.post('semester/addSemester', this.SemesterForm)
                if (status !== 200) {
                    return this.$message.error('添加专业失败！')
                }
                this.$message.success('添加专业成功！')
                this.getSemesterList()
                this.addSemesterDialogVisible = false
            })
        },
        // 添加年级
        addGrade () {
            this.$refs.addGradeFormRef.validate(async valid => {
                if (!valid) return
                const { data: res, status: status } = await this.axios.post('grade/addGrade', this.GradeForm);
                if (status !== 200) {
                    return this.$message.error('添加专业失败！')
                }
                this.$message.success('添加专业成功！');
                this.getGradeList();
                this.addGradeDialogVisible = false
            })
        },
        // 删除院系
        async removeDepartById (row) {
            const confirmResult = await this.$confirm(
                '此操作将永久删除部门 ' + row.name +  ',  是否继续?',
                '提示',
                {
                    confirmButtonText: '确定',
                    cancelButtonText: '取消',
                    type: 'warning'
                }
            ).catch(err => err)
            if (confirmResult !== 'confirm') {
                return this.$message.info('已取消删除')
            }
            const { data: res, status: status } = await this.axios.delete('department/deleteDepart', {params: {"id": row.id}})
            if (status !== 200) return this.$message.error('删除角色失败！')
            this.$message.success('删除用户成功！')
            this.getDepartList()
        },
        async removeMajorById (row) {
            const confirmResult = await this.$confirm(
                '此操作将永久删除部门 ' + row.name +  ',  是否继续?',
                '提示',
                {
                    confirmButtonText: '确定',
                    cancelButtonText: '取消',
                    type: 'warning'
                }
            ).catch(err => err)
            if (confirmResult !== 'confirm') {
                return this.$message.info('已取消删除')
            }
            const { data: res, status: status } = await this.axios.delete('major/deleteMajor', {params: {"id": row.id}})
            if (status !== 200) return this.$message.error('删除角色失败！')
            this.$message.success('删除用户成功！')
            this.getMajorList()
        },
        // 删除学期
        async removeSemesterById (row) {
            const confirmResult = await this.$confirm(
                '此操作将永久删除部门 ' + row.name +  ',  是否继续?',
                '提示',
                {
                    confirmButtonText: '确定',
                    cancelButtonText: '取消',
                    type: 'warning'
                }
            ).catch(err => err)
            if (confirmResult !== 'confirm') {
                return this.$message.info('已取消删除')
            }
            const { data: res, status: status } = await this.axios.delete('semester/deleteSemester', {params: {"id": row.id}})
            if (status !== 200) return this.$message.error('删除学期失败！');
            this.$message.success('删除学期成功！');
            this.getSemesterList()
        },
        // 删除年级
        async removeGradeById (row) {
            const confirmResult = await this.$confirm(
                '此操作将永久删除部门 ' + row.name +  ',  是否继续?',
                '提示',
                {
                    confirmButtonText: '确定',
                    cancelButtonText: '取消',
                    type: 'warning'
                }
            ).catch(err => err);
            if (confirmResult !== 'confirm') {
                return this.$message.info('已取消删除')
            }
            const { data: res, status: status } = await this.axios.delete('grade/deleteGrade', {params: {"id": row.id}});
            if (status !== 200) return this.$message.error('删除年级失败！');
            this.$message.success('删除年级成功！');
            this.getGradeList()
        },
        editDep(){
            this.$refs.editDepFormRef.validate(async valid => {
            if (valid) {
                const {data: res, status: status} = await this.axios.put("department/updateDepart", this.DepForm)
                if (status !== 200){
                    return this.$message.error("添加院系失败")
                }
                this.$message.success("修改院系成功")
                this.editDepDialogVisible = false
                this.DepForm = []
                this.getDepartList()
            }
            return;
            });
        },
        editMajor(){
            if (!this.MajorForm.department_id) {
                return this.$message.error("情选择所属院系") 
            }
            this.$refs.editMajorFormRef.validate(async valid => {
                if (!valid) return
                const { data: res, status: status } = await this.axios.put('major/updateMajor', this.MajorForm)
                if (status !== 200) {
                    return this.$message.error('添加专业失败！')
                }
                this.$message.success('添加专业成功！');
                this.getMajorList();
                this.MajorForm = [];
                this.editMajorDialogVisible = false
            })
        },
        editSemester(){
            this.$refs.editSemesterFormRef.validate(async valid => {
                if (!valid) return;
                const { data: res, status: status } = await this.axios.put('semester/updateSemester', this.SemesterForm);
                if (status !== 200) {
                    return this.$message.error('添加专业失败！')
                }
                this.$message.success('添加专业成功！');
                this.getSemesterList();
                this.SemesterForm = [];
                this.editSemesterDialogVisible = false
            })
        },
        editGrade(){
            this.$refs.editGradeFormRef.validate(async valid => {
                if (!valid) return
                const { data: res, status: status } = await this.axios.put('grade/updateGrade', this.GradeForm);
                if (status !== 200) {
                    return this.$message.error('添加专业失败！')
                }
                this.$message.success('添加专业成功！');
                this.getGradeList();
                this.GradeForm = [];
                this.editGradeDialogVisible = false
            })
        },
    }  
}
</script>
<style lang="less" scoped>
</style>